#!/bin/bash

export LC_ALL=C

COMPARE_TYPE=$1
COMPARE_FUNC=$2
BASE_ANN_DIR=$3

for GA_DIR in ${BASE_ANN_DIR}/annot_*; do

    GENE_ID=`head -n1 $GA_DIR/gene.faa | cut -b 2-`
    GENE_FUNCTION=`cat $GA_DIR/../genes_go.txt | grep ${GENE_ID} | cut -f2 | head -n1`

    echo -ne ${GENE_ID}'\t'$(basename $GA_DIR)

    for E_DIR in ${GA_DIR}/e_*; do
        RES=`zcat ${E_DIR}/results_gene_ontology.txt.gz | cut -f2 | 9_annotation_analysis/compare_gene_functions_go.py "${COMPARE_TYPE}" "${COMPARE_FUNC}" "${GENE_FUNCTION}"`
        echo -ne '\t'$RES
    done

    echo -e '\t'${GENE_FUNCTION}

done > ${BASE_ANN_DIR}/results_go_${COMPARE_TYPE}_${COMPARE_FUNC}.txt


